package iscte.iul.dcti.pa.al2011_12.model;

import java.util.ArrayList;
import java.util.List;

import javax.rmi.CORBA.Util;

import iscte.iul.dcti.pa.al2011_12.controller.MyApp;

import iscte.iul.dcti.pa.al2011_12.utilities.*; 

public class Sheet {
	private int numRows;
	private int numColumns;
	//private List<Cell> mySheet;
	private List<Row> rows;
	
	public Sheet (int numRows, int numColumns) {
		this.numRows = numRows;
		this.numColumns = numColumns;
		//mySheet = new ArrayList<Cell>();
		rows = new ArrayList<Row>();
		
		buildSheet();
	}

	private void buildSheet() {
		
		//char currentColumn, firstColumn = 'A';
		Row row;
		Cell cell;
		for (int i = 0; i < numRows; i++) {
			row = new Row();
			
			for (int j = 0; j < numColumns; j++) {
				cell = new Cell(j, i + 1);
				cell.addObserver(new MyApp());
				row.addCell(cell);
			
			}
			rows.add(row);
		}
	}
	
	public int getNumRows (){
		return numRows;
	}
	public int getNumColumns (){
		return numColumns;
	}
	public List<Row> getRows () {
		return rows;
	}
	
	public void setCellValue(String abscissa, int ordinate, String value) {
		Row row = rows.get(ordinate);
		Cell cell = row.getCells().get(Utils.GetColumnIndex(abscissa));
		cell.setValue(value);
	}
	
	public Row getRow(int ordinate) {
		return rows.get(ordinate);
	}
	
	public Cell getCell(String abscissa, int ordinate)
	{
		return getRow(ordinate).getCells().get(Utils.GetColumnIndex(abscissa));
	}
	public Cell getCell(int abscissa, int ordinate) {
		return getRow(ordinate).getCells().get(abscissa);
	}
}
